package Gui.Dialogs;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;

import Gui.GameFrame;
import Main.Defines;

public class EndTurnDialog extends JDialog {
	/**
	 * 
	 */
	private static final long serialVersionUID = 4032431689432117637L;
	private JPanel m_jp;
	private void buildUIContents() {
		JLabel info = new JLabel(String.format("Player %d Turn!", Defines.CP().getIDPrintable()));
		m_jp.add(info, BorderLayout.NORTH);
		JButton ok = new JButton("OK");

		ok.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				dispose();
				GameFrame.getInstance().update();

			}
		});
		m_jp.add(ok, BorderLayout.CENTER);
	}

	public EndTurnDialog() {
		//super(GameFrame.getInstance(), String.format("Player %d Turn!", Defines.CP().getIDPrintable()), true);
		setModalityType(getModalityType().APPLICATION_MODAL);
		m_jp = new JPanel(new BorderLayout(0,Defines.VERTICAL_PADDING));

		//m_jp.setLayout(new GridLayout(0, 1, 0, 10));
		m_jp.setBorder(Defines.getEmptyBorderConstraints());
		buildUIContents();
		add(m_jp);
		pack();
		
		if(getTitle() != null){
			FontMetrics fm = getFontMetrics(getFont());
			int width = fm.stringWidth(getTitle()) + Defines.ICON_WIDTH;
			width = (int) Math.max(width*1.2, getPreferredSize().getWidth());
			setSize(new Dimension(width, getHeight()));
		}
		setLocationRelativeTo(GameFrame.getInstance());
		setVisible(true);
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
	}
}
